var mysql = require('mysql');   // 引用mysql模块。注意要先安装mysql： npm install mysql
var config = require('./db');

var db    = {};

var pool = mysql.createPool(config.mysqllib);

//获取连接
db.getConnection = function(callback){
    pool.getConnection(function(err, connection) {
        console.log('获取连接')
        if (err) {
            callback(null);
            return;
        }
        callback(connection);
    });
}

module.exports = {
    db:db,
    pool:pool
};


// 新的数据库连接
//var newdb_pool = mysql.createPool(config. newdb);
//exports. newdb_pool = newdb_pool;